package org.ChrisRiffle.Acme.BoundingBox.controlers;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import org.ChrisRiffle.Acme.BoundingBox.ui.BoxQueryDialog;

/**
 * 
 * Controls communication with the Query Dialog
 * 
 * @author RIF
 */
public enum QueryDialogController {
    
	//singleton
    INSTANCE;
    
    
    private WindowAdapter boxDialogWindowAdapter;
    
    private BoxQueryDialog boxDialog;
    
    
    // 'loading' panel used when $$ work is being done
    public enum PANEL_TYPE{
	
		LOADING,
		READY	
    }
    

	/**
	 * displayPanelType
	 * 
	 * @param pPanelType
	 */
	public void displayPanelType(PANEL_TYPE pPanelType) {

		if (pPanelType == PANEL_TYPE.LOADING) {

			getBoxDialog().setContentPane(getBoxDialog().getLoadingPanel());

		} else if (pPanelType == PANEL_TYPE.READY) {

			getBoxDialog().setContentPane(
					QueryPanelControler.INSTANCE.getBoxQuerySwingPanel());

		}

	}
    
	
    
	/**
	 * Gets the boxDialog
	 * 
	 * @return the boxDialog
	 */
	public BoxQueryDialog getBoxDialog() {

		
		if (boxDialog == null) {

			boxDialog = new BoxQueryDialog();

			configBoxDialog(boxDialog);
		}
		return boxDialog;
	}
    
	
	
    
	/**
	 * configBoxDialog
	 * 
	 * @param pDialog
	 */
	private void configBoxDialog(BoxQueryDialog pDialog) {


		pDialog.addWindowListener(getDialogWindowListener());
		
	}

    
    
    
	/**
	 * getDialogWindowListener
	 * 
	 * @return DialogWindowListener
	 */
	private WindowAdapter getDialogWindowListener() {

		if (boxDialogWindowAdapter == null) {

			boxDialogWindowAdapter = new WindowAdapter() {

				public void windowClosing(WindowEvent e) {

					System.exit(0);
				};
			};
		}
		return boxDialogWindowAdapter;
	}
    
}


